<template>
  <div class="body-box">
    <el-form label-position="left" label-width="100px" size="small" class="info-form">
      <el-form-item label="跑团LOGO">
        <el-upload
          class="avatar-uploader"
          action="https://jsonplaceholder.typicode.com/posts/"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload"
        >
          <img v-if="info.Logo" :src="info.Logo" class="avatar" />
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>
      </el-form-item>
      <el-form-item label="跑团ID">
        <el-input readonly v-model="info.IdCode"></el-input>
      </el-form-item>
      <el-form-item label="跑团名称">
        <el-input v-model="info.Title"></el-input>
      </el-form-item>
      <el-form-item label="团长">
        <el-input readonly v-model="info.Contacter"></el-input>
      </el-form-item>
      <el-form-item label="联系方式">
        <el-input v-model="info.Contact"></el-input>
      </el-form-item>
      <el-form-item label="跑团地址">
          <span class="addr-link" @click="changeAddr()">{{info.Province}}{{info.City}}{{info.Address}}</span>
      </el-form-item>
      <el-form-item label="跑团口号">
        <el-input  type="textarea"  v-model="info.Slogan"></el-input>
      </el-form-item>
      <!-- <el-form-item label="跑团公告">
        <el-input  type="textarea"  v-model="info.Notice" class="team-kou"></el-input>
      </el-form-item> -->
      <el-form-item label="跑团介绍">
        <quill-editor
          :options="editorOption"
          ref="myQuillEditor"
          @ready="onEditorReady($event)"
          v-model="info.Detail"
          class="edit-itme"
        ></quill-editor>
      </el-form-item>
      <el-form-item>
          <el-button class="com-btn" icon="el-icon-check" @click="save()">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { quillEditor } from "vue-quill-editor";
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
import infoAddr from "./info-addr.vue";
import quillConfig from '../../assets/js/quill-config.js'

export default {
  components: { quillEditor , infoAddr },
  data() {
    return {
      imageUrl: "",
      form:{
          detail:''
      },
      info:{},
      editorOption: quillConfig
    };
  },
  computed: {
    editor() {
      return this.$refs.myQuillEditor.quill;
    }
  },
  mounted(){
    this.getData();
  },
  methods: {
    //保存信息
    save(){
      this.ajaxs('club/saveInfo',{
        data : this.info,
        success:(res) => {
          this.toast(res.code,res.msg);
        }
      });
      console.log(this.info);
    },
    //获取跑团信息
    getData(){
      this.ajaxs('club/getClubInfo',{
        success:(res) => {
          this.info = res.msg;
          console.log(this.info);
        }
      });
    },
    onEditorReady(editor) {},
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
    },
    //修改地址
    changeAddr(){
        this.$layer.iframe({
        content: {
          content: infoAddr, //传递的组件对象
          parent: this, //当前的vue对象
          data: {} //props
        },
        area: ["800px", "600px"],
        title: "切换地址"
      });
    }
  }
};
</script>

<style>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 100px;
  height: 100px;
  line-height: 100px;
  text-align: center;
}
.avatar {
  width: 100px;
  height: 100px;
  display: block;
}
.edit-itme{
    height: 400px;
    margin-bottom: 80px;
}
.info-form{
    width: 800px;
}
.addr-link{
    color:#8a70c6;
    cursor: pointer;
}
.team-kou > textarea{
  height: 100px;
}
</style>